#! /bin/bash

getopts "bsc" ops

if [ "$ops" = \? ]
then 
    echo "Usage: $0 -b | -s | -c"
    echo "       -b: both copy and save to file"
    echo "       -s: just save to file"
    echo "       -c: just copy"
    exit 0
fi

AREA=$(slurp -d)

if [ $? = 1 ]; then
    echo "Area not selected!"
    exit 0
fi

FILENAME="$HOME/$(date +'%Y-%m-%d_%H-%M-%S').png"

case $ops in
    b)
        grim -g "$AREA" - | tee "$FILENAME" | wl-copy
        echo "Screenshot copied and also saved to: $FILENAME" ;;
    s)
        grim -g "$AREA" "$FILENAME"
        echo "Screenshot saved to: $FILENAME" ;;
    c)
        grim -g "$AREA" - | wl-copy
        echo "Screenshot copied" ;;
esac
